#include <iostream>
using namespace std;

/*
    前置++
    后置++
        1.无论是前置++还是后置++，重载的时候，函数名字都叫做operator++()
        2，分析发现前置++跟后置的++，同名，同参，同返回值类型，无法区分
          C++提供解决方案，后置的自增，需要添加一个int类型的参数（跟前置的自增做区分）
          必须是int
*/

class Cat
{
public:
    Cat(string name, int age)
    {
        this->name = name;
        this->age = age;
    }

    Cat operator++(int n)
    {
        Cat temp = *this;
        this->age++;
        return temp;
    }

    Cat operator++()
    {
        this->age++;
        return *this;
    }

    void show() const
    {
        cout << "name: " << name << " age: " << age << endl;
    }

private:
    string name;
    int age;
};

int main()
{
    Cat c1("Tom", 2);

    // 后置++
    Cat c2 = c1.operator++(666); // c1++;
    // Cat c2 = c1++;            // c2 = c1; c1++;

    c1.show();
    c2.show();

    // 前置++
    Cat c3 = c1.operator++(); // ++c1;
    // Cat c3 = ++c1;            // ++c1;
    c1.show();
    c3.show();
}